package com.jt.tenant.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetInsQuote;
import com.jt.tenant.widget.Tools;

import java.util.List;

/**
 * Created by Administrator on 2016/4/6.
 */
public class InsOfferLevel2Adapter extends BaseAdapter {

    private Context context;

    private List<GetInsQuote.QuoteItem> level2_list;

    private LayoutInflater inflater;

    private ViewHolder holder = null;

    @SuppressLint("UseSparseArrays")
    public InsOfferLevel2Adapter(Context context, List<GetInsQuote.QuoteItem> list){

        this.level2_list = list;

        this.context = context;

        inflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {

        return level2_list.size();

    }

    @Override
    public Object getItem(int position) {

        return level2_list.get(position);

    }

    @Override
    public long getItemId(int position) {

        return position;

    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        holder = new ViewHolder();

        if(convertView == null){

            convertView = View.inflate(context, R.layout.item_ins_offer_2,null);

            JTApplication.ScaleScreenHelper.loadView((ViewGroup)convertView);

            holder = new ViewHolder();

            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_ins_quote_item_name);

            holder.tv_money = (TextView) convertView.findViewById(R.id.tv_ins_quote_item_money);

            holder.tv_price = (TextView) convertView.findViewById(R.id.tv_ins_quote_item_price);

            holder.lin_iop = (LinearLayout)convertView.findViewById(R.id.lin_ins_quote_item_iop);

            holder.tv_iop = (TextView)convertView.findViewById(R.id.tv_ins_quote_item_iop);

            convertView.setTag(holder);

        }else{

            holder = (ViewHolder) convertView.getTag();

        }

        holder.tv_name.setText(level2_list.get(position).name);

        if(Tools.F_num(level2_list.get(position).money).equals("0")){

            holder.tv_money.setText("待查询");

        }else if(Tools.F_num(level2_list.get(position).money).equals("1")){

            holder.tv_money.setText("国产");

        }else if(Tools.F_num(level2_list.get(position).money).equals("2")){

            holder.tv_money.setText("进口");

        }else {

            holder.tv_money.setText(String.valueOf(Integer.parseInt(level2_list.get(position).money)*Integer.parseInt(level2_list.get(position).num))+"元");

        }

        holder.tv_price.setText(Tools.F_num(level2_list.get(position).price)+"元");

        if(!level2_list.get(position).flag.equals("0")){

            holder.lin_iop.setVisibility(View.VISIBLE);

            holder.tv_iop.setText(level2_list.get(position).flag_money+"元");

        }



        return convertView;

    }

    class ViewHolder{

        TextView tv_name;//tv_ins_quote_item_name

        TextView tv_money;

        TextView tv_price;

        LinearLayout lin_iop;

        TextView tv_iop;

    }

}
